package com.gimi.cloud.bbp.manage.consumer.service.mall.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.JsonUtil;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.dto.mall.MallAppSpecialGroupDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.MallFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.mall.MallSpecialGroupService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * app专场组管理
 * @author chendi
 * @date 2018年1月31日
 */
@Service
public class MallSpecialGroupServiceImpl implements MallSpecialGroupService{
    private static final Logger logger = LoggerFactory.getLogger(MallSpecialGroupServiceImpl.class);

    private MallFeignService mallFeignService;

    @Autowired
    public MallSpecialGroupServiceImpl(MallFeignService mallFeignService) {
        this.mallFeignService = mallFeignService;
    }

    @Override
    public Response getSpecialGroupList(HttpServletRequest request, HttpServletResponse response, MallAppSpecialGroupDTO dto) throws Exception {
    	return mallFeignService.getAppSpecialGroupList(dto);
    }

    @Override
    public Response getSpecialGroupInfo(HttpServletRequest request, HttpServletResponse response, MallAppSpecialGroupDTO dto) throws Exception {
        if(null == dto.getAsgId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"专场组id为空，获取专场组列表失败");
            Util.sendResponse(JsonUtil.toJson(resp), response);
            return resp;
        }
        return mallFeignService.getAppSpecialGroupInfo(dto);
    }

    @Override
    public Response addSpecialGroup(HttpServletRequest request, HttpServletResponse response, MallAppSpecialGroupDTO dto) throws Exception {
        if(null != dto.getAsgId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"专场组Id不为空，添加专场组信息失败");
            return resp;
        }
        return mallFeignService.saveOrUpdateSpecialGroup(dto);
    }

    @Override
    public Response editSpecialGroup(HttpServletRequest request, HttpServletResponse response, MallAppSpecialGroupDTO dto) throws Exception {
        if(null == dto.getAsgId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"专场组Id为空，修改专场组信息失败");
            return resp;
        }
        return mallFeignService.saveOrUpdateSpecialGroup(dto);
    }

    @Override
    public Response deleteSpecialGroup(HttpServletRequest request, HttpServletResponse response, MallAppSpecialGroupDTO dto) throws Exception {
        if(null == dto.getAsgId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"专场组Id为空，删除专场组信息失败");
            return resp;
        }
        return mallFeignService.deleteSpecialGroup(dto);
    }
}
